package net.xuwu.marry.service.file.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import net.sf.json.JSONArray;
import net.xuwu.marry.service.file.bean.FristLevelBean;
import net.xuwu.marry.service.file.bean.SecondLevelBean;
import net.xuwu.marry.service.file.dao.IFileDao;

import com.opensymphony.xwork2.ActionSupport;

public class FileAction extends ActionSupport {

	private IFileDao fileDao;
	private String result="";
	
	
	public FileAction() {
		System.out.println("init finshed....");
	}

	/**
	 * 得到一级目录
	 * @return
	 */
	public String getFirst(){
		
		try {
			List<FristLevelBean> frist =fileDao.getFristLevel();
			JSONArray json = JSONArray.fromObject(frist);
			result = json.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return "getfile";
	}

	/**
	 * 得到二级目录
	 * @return
	 */
	public String getSecond(){
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			int fristLevelId = Integer.parseInt(request.getParameter("fristId"));
			List<SecondLevelBean> list = fileDao.getSecondLevel(fristLevelId);
			JSONArray json = JSONArray.fromObject(list);
			result = json.toString();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "getsecond";
	}
	
	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public void setFileDao(IFileDao fileDao) {
		this.fileDao = fileDao;
	}
	
}
